package nc.bs.arap.selectedpay;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;

import javax.naming.NamingException;

import nc.bs.pub.SystemException;
import nc.vo.arap.exception.ExceptionHandler;
import nc.vo.arap.selectedpay.DMO;
import nc.vo.arap.selectedpay.XzfkVO;
import nc.vo.pub.lang.UFDouble;

public class XZFKDMO extends DMO {

	public XZFKDMO() throws NamingException, SystemException {
		super();
	}

	public Vector<XzfkVO> getByPrimaryKeys(String[] keys,String pk_corp) throws SQLException {

     	try
		{
     		Connection connection = null;
    		PreparedStatement statement = null;
    		ResultSet rs = null;
     		connection=this.getConnection();
     		Vector<XzfkVO> result = new Vector<XzfkVO>();
     		
     		StringBuffer sql=new StringBuffer();
     		if(keys==null || keys.length==0)
     		{
     			return result;
     		}
     		
     		sql.append("select fkje,fkye,pk,sfb_oid,svouchid,tfb_oid,tvouchid from arap_xzfk where dr=0 and pk in(");
     		for(int i=0;i<keys.length;i++)
     		{
     			if(i==keys.length-1)
     			{
     				sql.append("'"+keys[i]+"')");
     			}
     			else
     			{
     				sql.append("'"+keys[i]+"',");
     			}
     		}

			statement = connection.prepareStatement(sql.toString());
			rs = statement.executeQuery();
			
			while (rs.next()) {
				XzfkVO vo = new XzfkVO();
				
				vo.setFkje(new UFDouble(rs.getDouble(1)));
				vo.setFkye(new UFDouble(rs.getDouble(2)));
				
				String temp = rs.getString(3);
				vo.setPk(temp != null && temp.length() != 0 ? temp : null);
				temp = rs.getString(4);
				vo.setSfb_oid(temp != null && temp.length() != 0 ? temp : null);
				temp = rs.getString(5);
				vo.setSvouchid(temp != null && temp.length() != 0 ? temp : null);
				temp = rs.getString(6);
				vo.setTfb_oid(temp != null && temp.length() != 0 ? temp : null);
				temp = rs.getString(7);
				vo.setTvouchid(temp != null && temp.length() != 0 ? temp : null);
				

				result.add(vo);
			}
  
     		return result;

		}
     	catch(SQLException e)
		{
     		ExceptionHandler.consume(e);
     		throw e;
		}
     	catch(Exception e)
		{
     		ExceptionHandler.consume(e);
     		throw new SQLException(e.getMessage());
		}
     	
    }
}
